
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 12/08/2012 23:32:28
-- Generated from EDMX file: D:\_TFS\WorkingWU\Solution\Solution\MasterEDM.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [iap_wwu];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_CategoryCategory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_CategoryCategory];
GO
IF OBJECT_ID(N'[dbo].[FK_CategoryContent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contents] DROP CONSTRAINT [FK_CategoryContent];
GO
IF OBJECT_ID(N'[dbo].[FK_ContentDetailContent]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[DetailContents] DROP CONSTRAINT [FK_ContentDetailContent];
GO
IF OBJECT_ID(N'[dbo].[FK_Contents_Authors]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contents] DROP CONSTRAINT [FK_Contents_Authors];
GO
IF OBJECT_ID(N'[dbo].[FK_LanguageCategory]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Categories] DROP CONSTRAINT [FK_LanguageCategory];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Authors]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Authors];
GO
IF OBJECT_ID(N'[dbo].[Categories]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Categories];
GO
IF OBJECT_ID(N'[dbo].[Contents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contents];
GO
IF OBJECT_ID(N'[dbo].[DetailContents]', 'U') IS NOT NULL
    DROP TABLE [dbo].[DetailContents];
GO
IF OBJECT_ID(N'[dbo].[Languages]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Languages];
GO
IF OBJECT_ID(N'[dbo].[sysdiagrams]', 'U') IS NOT NULL
    DROP TABLE [dbo].[sysdiagrams];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Languages'
CREATE TABLE [dbo].[Languages] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Code] nvarchar(max)  NULL,
    [Name] nvarchar(max)  NULL,
    [IsDefault] bit  NULL,
    [Enabled] bit  NULL,
    [Status] smallint  NULL,
    [DisplayOrder] smallint  NULL
);
GO

-- Creating table 'Categories'
CREATE TABLE [dbo].[Categories] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Thumb] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NULL,
    [Intro] nvarchar(max)  NULL,
    [Detail] nvarchar(max)  NULL,
    [Views] smallint  NULL,
    [Enabled] bit  NULL,
    [Status] smallint  NULL,
    [CreatedDate] datetime  NULL,
    [DisplayOrder] smallint  NULL,
    [Parent_Id] int  NULL,
    [Language_Id] int  NOT NULL
);
GO

-- Creating table 'Contents'
CREATE TABLE [dbo].[Contents] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Thumb] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NULL,
    [Intro] nvarchar(max)  NULL,
    [Detail] nvarchar(max)  NULL,
    [Views] smallint  NULL,
    [Enabled] bit  NULL,
    [Status] smallint  NULL,
    [CreatedDate] datetime  NULL,
    [DisplayOrder] smallint  NULL,
    [Category_Id] int  NULL,
    [Author_Id] int  NULL
);
GO

-- Creating table 'DetailContents'
CREATE TABLE [dbo].[DetailContents] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Thumb] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NULL,
    [Intro] nvarchar(max)  NULL,
    [Detail] nvarchar(max)  NULL,
    [Views] smallint  NULL,
    [Enabled] bit  NULL,
    [Status] smallint  NULL,
    [CreateDate] datetime  NULL,
    [DisplayOrder] smallint  NULL,
    [Content_Id] int  NULL
);
GO

-- Creating table 'Authors'
CREATE TABLE [dbo].[Authors] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(max)  NULL,
    [Thumb] nvarchar(max)  NULL,
    [Title] nvarchar(max)  NULL,
    [Intro] nvarchar(max)  NULL,
    [Detail] nvarchar(max)  NULL,
    [Views] smallint  NULL,
    [Enabled] bit  NULL,
    [Status] smallint  NULL,
    [CreatedDate] datetime  NULL,
    [DisplayOrder] smallint  NULL
);
GO

-- Creating table 'sysdiagrams'
CREATE TABLE [dbo].[sysdiagrams] (
    [name] nvarchar(128)  NOT NULL,
    [principal_id] int  NOT NULL,
    [diagram_id] int IDENTITY(1,1) NOT NULL,
    [version] int  NULL,
    [definition] varbinary(max)  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Languages'
ALTER TABLE [dbo].[Languages]
ADD CONSTRAINT [PK_Languages]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [PK_Categories]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contents'
ALTER TABLE [dbo].[Contents]
ADD CONSTRAINT [PK_Contents]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'DetailContents'
ALTER TABLE [dbo].[DetailContents]
ADD CONSTRAINT [PK_DetailContents]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Authors'
ALTER TABLE [dbo].[Authors]
ADD CONSTRAINT [PK_Authors]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [diagram_id] in table 'sysdiagrams'
ALTER TABLE [dbo].[sysdiagrams]
ADD CONSTRAINT [PK_sysdiagrams]
    PRIMARY KEY CLUSTERED ([diagram_id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Parent_Id] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [FK_CategoryCategory]
    FOREIGN KEY ([Parent_Id])
    REFERENCES [dbo].[Categories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryCategory'
CREATE INDEX [IX_FK_CategoryCategory]
ON [dbo].[Categories]
    ([Parent_Id]);
GO

-- Creating foreign key on [Category_Id] in table 'Contents'
ALTER TABLE [dbo].[Contents]
ADD CONSTRAINT [FK_CategoryContent]
    FOREIGN KEY ([Category_Id])
    REFERENCES [dbo].[Categories]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CategoryContent'
CREATE INDEX [IX_FK_CategoryContent]
ON [dbo].[Contents]
    ([Category_Id]);
GO

-- Creating foreign key on [Language_Id] in table 'Categories'
ALTER TABLE [dbo].[Categories]
ADD CONSTRAINT [FK_LanguageCategory]
    FOREIGN KEY ([Language_Id])
    REFERENCES [dbo].[Languages]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LanguageCategory'
CREATE INDEX [IX_FK_LanguageCategory]
ON [dbo].[Categories]
    ([Language_Id]);
GO

-- Creating foreign key on [Content_Id] in table 'DetailContents'
ALTER TABLE [dbo].[DetailContents]
ADD CONSTRAINT [FK_ContentDetailContent]
    FOREIGN KEY ([Content_Id])
    REFERENCES [dbo].[Contents]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContentDetailContent'
CREATE INDEX [IX_FK_ContentDetailContent]
ON [dbo].[DetailContents]
    ([Content_Id]);
GO

-- Creating foreign key on [Author_Id] in table 'Contents'
ALTER TABLE [dbo].[Contents]
ADD CONSTRAINT [FK_Contents_Authors]
    FOREIGN KEY ([Author_Id])
    REFERENCES [dbo].[Authors]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Contents_Authors'
CREATE INDEX [IX_FK_Contents_Authors]
ON [dbo].[Contents]
    ([Author_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------